class Light {
    public void turnLight(int degree){
        System.out.println("灯的亮度是"+degree);
        //调整灯的亮度
    }
}
class TV {
    public void setChannel(int channel){
        //设置频道
        System.out.println("频道是"+channel);
    }
}
interface Command {
    void on();
    void off();
}
class RemoteController {
    protected Command[] commands=new Command[4];
    public void onPressButton(int button){
        if (button%2==0){
            commands[button].on();
    }else {
            commands[button].off();
        }
    }
    public void setCommand(int button,Command command){
        commands[button]=command;
    }
}
class LightOnCommand implements Command {
    protected Light light;
    public LightOnCommand(Light light){
        this.light=light;
    }
    public void on(){
        light.turnLight(100);
    }
    public void off(){
        light.turnLight(0);
    }
}
class TVOnCommand implements Command {
    protected TV tv;
    public void on(){
        tv.setChannel(1);
    }
    public void off(){
        tv.setChannel(0);
    }

    public TVOnCommand(TV tv) {
        this.tv = tv;
    }
}
public class Test {
    public static void main(String[] args) {
    Light light=new Light();
    TV tv=new TV();
    Command lightCommand=new LightOnCommand(light);
    Command tvCommand=new TVOnCommand(tv);

//    设置遥控器的按钮，0,1号按钮是灯，2,3号按钮是电视
    RemoteController remoteController=new RemoteController();
    remoteController.setCommand(0,lightCommand);
    remoteController.setCommand(1,lightCommand);
    remoteController.setCommand(2,tvCommand);
    remoteController.setCommand(3,tvCommand);

//    按下按钮
    remoteController.onPressButton(0);
    remoteController.onPressButton(1);
    remoteController.onPressButton(2);
    remoteController.onPressButton(3);
    }
}
